#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QSound>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    initScene();
    connect(ui->startButton,&QPushButton::clicked,[=]()
    {
        QSound* startbtn=new QSound(":/picture/sound/TapButton.wav");
        startbtn->play();
        game_page=new GameWindow;
        game_page->show();
    });
    rule_page=new rule;
    ui->stackedWidget->addWidget(rule_page);
    connect(ui->ruleButton,&QPushButton::clicked,[=](){
        QSound* rulebtn=new QSound(":/picture/sound/TapButton.wav");
        rulebtn->play();
        ui->stackedWidget->setCurrentWidget(rule_page);
    });
    connect(rule_page,&rule::closeWindow,[=](){
        ui->stackedWidget->setCurrentWidget(ui->page);
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::initScene()
{
    setFixedSize(MAIN_WIDTH,MAIN_HEIGHT);
    setWindowTitle(GAME_TITLE);
    setWindowIcon(QIcon(":/picture/images/me1.png"));
    QSound* startSound=new QSound(":/picture/sound/Main_sound.wav");
    startSound->setLoops(-1);
    startSound->play();
}


void MainWindow::on_pushButton_3_clicked()
{
    QSound* backbtn3=new QSound(":/picture/sound/TapButton.wav");
    backbtn3->play();
    close();
}
